local key1 = "addresslist:id:" .. KEYS[1]
local key2 = "addresslist:id:" .. KEYS[2]
local key3 = "chat:caht_list:ID_" .. KEYS[1]
local key4 = "chat:caht_list:ID_" .. KEYS[2]
local key5 = "chat:chat_object:ID_" .. KEYS[1] .. ":" .. KEYS[2]
local key6 = "chat:chat_object:ID_" .. KEYS[2] .. ":" .. KEYS[1]
local key7 = "addresslist:friendList:ID_" .. KEYS[1]
local key8 = "addresslist:friendList:ID_" .. KEYS[2]
local timestamp = tonumber(ARGV[3])

redis.call('SADD', key1,ARGV[2])
redis.call('SADD', key2,ARGV[1])
redis.call('ZADD', key3, timestamp,ARGV[2])
redis.call('ZADD', key4, timestamp,ARGV[1])

redis.call('HSET', key5, 'content', ARGV[4])
redis.call('HSET', key5, 'tip', ARGV[5])
redis.call('HSET', key5, 'time', ARGV[6])
redis.call('HSET', key6, 'content', ARGV[4])
redis.call('HSET', key6, 'tip', ARGV[5])
redis.call('HSET', key6, 'time', ARGV[6])

if redis.call('EXISTS',key7) == 1 then
    redis.call('DEL',key7)
end
if redis.call('EXISTS',key8) == 1 then
    redis.call('DEL',key8)
end
return